﻿using AutoMapper;
using FarmSmartSleep.Common.Domain.PM.select;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.FemaleRen
{
    public class FemaleRenWayHandler : IRequestHandler<FemaleRenWayCommand, Result>
    {
        public IBaseRepository<PregnancyTests> pregnancyTestsRepository;

        public IBaseRepository<PregnancyCheckMethod> pregnancyCheckMethodRepository;

        public IMapper mapper;

        public FemaleRenWayHandler(IBaseRepository<PregnancyTests> pregnancyTestsRepository, IBaseRepository<PregnancyCheckMethod> pregnancyCheckMethodRepository, IMapper mapper)
        {
            this.pregnancyTestsRepository = pregnancyTestsRepository;
            this.pregnancyCheckMethodRepository = pregnancyCheckMethodRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 妊检方式下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<Result> Handle(FemaleRenWayCommand request, CancellationToken cancellationToken)
        {
            Result result = new Result();
            result.Code = 1;
            result.Messege = "成功";
            var res = pregnancyCheckMethodRepository.GetAll().ToList();
            List<FemaleRenWayListCommand> lists = new List<FemaleRenWayListCommand>();
            foreach (var item in res)
            {
                var sf = mapper.Map<FemaleRenWayListCommand>(item);
                lists.Add(sf);
            }
            result.Data = lists;
            return Task.FromResult(result);
        }
    }
}
